package cn.com.gainfo.recks.action.bankCardPayBack;

import cn.yzyue.base.action.AbstractAction;
import cn.yzyue.base.tools.str.StrUtil;
import cn.yzyue.base.tools.tag.impl.CondItem;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class SubAction extends AbstractAction {
	protected String getSqlCondtion(HttpServletRequest request, List data) {
		String sqlCondtion = "";
		if (data != null) {
			for (int i = 0; i < data.size(); ++i) {
				CondItem ci = (CondItem) data.get(i);
				String name = ci.getDbFieldName();
				String value = StrUtil.getByPage(request.getParameter(name));
				if ((value != null) && (!value.trim().equals(""))) {
					if (ci.getFieldType().equals("3")) {
						if (name.endsWith("1")) {
							String key = name.substring(0, name.length() - 1);
							log.debug("key = [" + key + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + key + " >= '" + value + " 00:00:00' and ";
						} else if (ci.getDbFieldName().endsWith("2")) {
							String key = name.substring(0, name.length() - 1);
							log.debug("key = [" + key + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + key + " <= '" + value + " 23:59:59' and ";
						} else {
							log.debug("key = [" + name + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + name + " like '" + value + "%' and ";
						}
					} else if (ci.getFieldType().equals("4")) {
						if (name.endsWith("1")) {
							String key = name.substring(0, name.length() - 1);
							log.debug("key = [" + key + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + key + " >= '" + value + " 00:00:00' and ";
						} else if (ci.getDbFieldName().endsWith("2")) {
							String key = name.substring(0, name.length() - 1);
							log.debug("key = [" + key + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + key + " <= '" + value + " 23:59:59' and ";
						} else {
							log.debug("key = [" + name + "], value = [" + value + "]");
							sqlCondtion = sqlCondtion + name + " like '" + value + "%' and ";
						}
					} else if (ci.getFieldType().equals("1")) {
						log.debug("key = [" + name + "], value = [" + value + "]");
						sqlCondtion = sqlCondtion + name + " = '" + value + "' and ";
					} else if (ci.getFieldType().equals("2")) {
						log.debug("key = [" + name + "], value = [" + value + "]");
						sqlCondtion = sqlCondtion + name + " like '%" + value + "%' and ";
					}
				}
			}
			sqlCondtion = sqlCondtion.trim();
			if (sqlCondtion.endsWith("and"))
				sqlCondtion = sqlCondtion.substring(0, sqlCondtion.length() - 3);
		}
		return sqlCondtion;
	}
}